package com.hyperboost.backend.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hyperboost.common.annotation.Log;
import com.hyperboost.common.core.controller.BaseController;
import com.hyperboost.common.core.domain.AjaxResult;
import com.hyperboost.common.enums.BusinessType;
import com.hyperboost.backend.domain.OpportunityCategory;
import com.hyperboost.backend.service.IOpportunityCategoryService;
import com.hyperboost.common.utils.poi.ExcelUtil;
import com.hyperboost.common.core.page.TableDataInfo;

/**
 * 机会分类Controller
 * 
 * @author LXY
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/backend/opportunityCategory")
public class OpportunityCategoryController extends BaseController
{
    @Autowired
    private IOpportunityCategoryService opportunityCategoryService;

    /**
     * 查询机会分类列表
     */
    @PreAuthorize("@ss.hasPermi('backend:opportunityCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(OpportunityCategory opportunityCategory)
    {
        startPage();
        List<OpportunityCategory> list = opportunityCategoryService.selectOpportunityCategoryList(opportunityCategory);
        return getDataTable(list);
    }

    /**
     * 导出机会分类列表
     */
    @PreAuthorize("@ss.hasPermi('backend:opportunityCategory:export')")
    @Log(title = "机会分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OpportunityCategory opportunityCategory)
    {
        List<OpportunityCategory> list = opportunityCategoryService.selectOpportunityCategoryList(opportunityCategory);
        ExcelUtil<OpportunityCategory> util = new ExcelUtil<OpportunityCategory>(OpportunityCategory.class);
        util.exportExcel(response, list, "机会分类数据");
    }

    /**
     * 获取机会分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('backend:opportunityCategory:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(opportunityCategoryService.selectOpportunityCategoryByCategoryId(categoryId));
    }

    /**
     * 新增机会分类
     */
    @PreAuthorize("@ss.hasPermi('backend:opportunityCategory:add')")
    @Log(title = "机会分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OpportunityCategory opportunityCategory)
    {
        return toAjax(opportunityCategoryService.insertOpportunityCategory(opportunityCategory));
    }

    /**
     * 修改机会分类
     */
    @PreAuthorize("@ss.hasPermi('backend:opportunityCategory:edit')")
    @Log(title = "机会分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OpportunityCategory opportunityCategory)
    {
        return toAjax(opportunityCategoryService.updateOpportunityCategory(opportunityCategory));
    }

    /**
     * 删除机会分类
     */
    @PreAuthorize("@ss.hasPermi('backend:opportunityCategory:remove')")
    @Log(title = "机会分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(opportunityCategoryService.deleteOpportunityCategoryByCategoryIds(categoryIds));
    }
}
